<template>
  <el-container style="min-height: 100vh;">
    <el-header class="page-header">
      <span>{{ pageTitle }}</span>
      <el-button type="danger" @click="logout"  v-if="showHeaderButton">退出</el-button>
    </el-header>
    <el-main style="padding-bottom: 80px; padding-top: 40px;">
      <router-view></router-view>
    </el-main>
    <el-footer style="padding: 0; height: auto;" v-if="showFooter">
      <el-row justify="center" class="button-group">
        <el-col :span="24">
          <el-button-group class="adaptive-button-group">
            <el-button type="primary" @click="navigateTo('ActivityList')">活动列表</el-button>
            <el-button type="primary" @click="navigateTo('ActivityManagement')">活动管理</el-button>
            <!-- <el-button type="primary" @click="navigateTo('CheckinManagement')">签到管理</el-button> -->
            <el-button type="primary" @click="navigateTo('UserManagement')">用户管理</el-button>
            <el-button type="primary" @click="navigateTo('PointsManagement')">积分管理</el-button>
          </el-button-group>
        </el-col>
      </el-row>
    </el-footer>
  </el-container>
</template>

<script setup>
import { computed } from 'vue';
import { useRouter, useRoute } from 'vue-router';

const router = useRouter();
const route = useRoute();

const pageTitle = computed(() => {
  return route.meta.title || '管理后台'; // Default title if not set
});

const showHeaderButton = computed(() => {
  return typeof route.meta.headerButton !== 'undefined' ? route.meta.headerButton : true;
});

const showFooter = computed(() => {
  return typeof route.meta.footer !== 'undefined' ? route.meta.footer : true;
});

const navigateTo = (routeName) => {
  if (route.name !== routeName) {
    router.push({ name: routeName });
  }
};

const logout = () => {
  localStorage.removeItem('token');
  router.push('/login');
};
</script>

<style scoped>
.page-header {
  position: fixed;
  top: 0;
  width: 100%;
  font-size: 24px;
  font-weight: bold;
  text-align: center;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: #ffffff;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  z-index: 1000;
}

.button-group {
  position: fixed; 
  bottom: 0; 
  left: 0; 
  right: 0; 
  padding:5px; 
  background-color: #fff; 
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  width: 100%; 
  z-index: 1000;
}

.adaptive-button-group {
  display: flex;
  flex-wrap: nowrap; /* 禁止换行 */
  gap: 6px; /* 可选间距 */
  padding: 10px 0;
  overflow: hidden; /* 防止溢出 */
}

.adaptive-button-group .el-button {
  flex: 1; /* 等分宽度 */
  min-width: auto; /* 允许最小化 */
  white-space: nowrap;
  font-size: 14px;
  padding: 10px 6px; /* 减少内边距让按钮更紧凑 */
  box-sizing: border-box;
  text-align: center;
  transition: all 0.2s ease;
}
</style>